package rcs34.android.AndroidRC;

import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;

public class ARCTelephonyListener extends PhoneStateListener {
  TelephonyManager tm;

  public ARCTelephonyListener() {
    tm = (TelephonyManager) GApp.context
        .getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(this, PhoneStateListener.LISTEN_CALL_STATE
        | LISTEN_SIGNAL_STRENGTHS);
  }
  
  public void unregister(){
    tm.listen(this, LISTEN_NONE);
  }

  public void onCallStateChanged(int _state, String _number) {
    Intent i = new Intent(GApp.context, ServiceSender.class);
    /*i.putExtra(ServiceSender.KEY_CMD, ARCUtils.CMD_CALLSTATEINFO);
    int state = -1;
    switch (_state) {
    case TelephonyManager.CALL_STATE_IDLE:
      state = ARCUtils.CALL_STATE_IDLE;
      break;
    case TelephonyManager.CALL_STATE_OFFHOOK:
      state = ARCUtils.CALL_STATE_OFFHOOK;
      break;
    case TelephonyManager.CALL_STATE_RINGING:
      state = ARCUtils.CALL_STATE_RINGING;
      break;
    }
    i.putExtra(ARCUtils.EXTRA_CALL_STATE, state);
    i.putExtra(ARCUtils.EXTRA_CALL_NUMBER, _number);*/
    GApp.context.startService(i);
  }

  public void onServiceStateChanged(ServiceState _serviceState) {
    System.out.println(_serviceState);
  }
}
